package org.com.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.com.pojo.ProductImages;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import java.util.Map;
import java.util.List;

/**
* @author 86134
* @description 针对表【product_images】的数据库操作Mapper
* @createDate 2025-02-27 16:33:36
*/
@Repository
public interface ProductImagesMapper extends BaseMapper<ProductImages> {
    
    /**
     * 获取指定农场的所有商品图片
     * 通过 JOIN 查询获取指定农场ID下所有商品的图片
     * @param farmId 农场ID
     * @return 商品图片列表
     */
    @Select("SELECT pi.* FROM product_images pi " +
           "INNER JOIN products p ON pi.product_id = p.product_id " +
           "WHERE p.farm_id = #{farmId}")
    List<ProductImages> getImagesByFarmId(Integer farmId);

    /**
     * 获取指定商品的分类信息
     * @param productId 商品ID
     * @return 商品分类信息列表
     */
    @Select("SELECT c.category_id, c.name as category_name " +
           "FROM product_categories pc " +
           "LEFT JOIN categories c ON pc.category_id = c.category_id " +
           "WHERE pc.product_id = #{productId}")
    List<Map<String, Object>> getProductCategories(Integer productId);

    /**
     * 获取指定农场所有商品的分类信息
     * @param farmId 农场ID
     * @return 商品分类信息列表
     */
    @Select("SELECT p.product_id, c.category_id, c.name as category_name " +
           "FROM products p " +
           "LEFT JOIN product_categories pc ON p.product_id = pc.product_id " +
           "LEFT JOIN categories c ON pc.category_id = c.category_id " +
           "WHERE p.farm_id = #{farmId}")
    List<Map<String, Object>> getProductCategoriesByFarmId(Integer farmId);
}




